<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>编辑标签</title>
</head>
<body>
<script type="text/html" id="form">
    <input type="hidden" name="id" value="{{ d.id }}" />
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <text title="必填项" style="color:red;">*</text>
                    乐谱名称</label>
                <div class="layui-input-block">
                    <input type="text" name="name" value="{{d.name}}" lay-verify="required" autocomplete="off" placeholder="请输入乐谱名称"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <text title="必填项" style="color:red;">*</text>
                    作者名称</label>
                <div class="layui-input-block">
                    <input type="text" name="author" value="{{d.author}}" lay-verify="required" autocomplete="off" placeholder="请输入作者名称"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <text style="color:red;">图片尺寸建议 1:1比例</text>
                <label class="layui-form-label">
                    <text title="必填项" style="color:red;">*</text>
                    作者头像</label>
                <div class="layui-input-block">
                    <div class="laytpUpload"
                         data-name="avatar"
                         data-dir="xm_game/skym/music/avatar"
                         data-accept="image"
                         data-type="ali-oss"
                         data-layVerify="required"
                         data-showChoiceBtn="false"
                         data-uploadedId="{{d.avatar}}"
                         data-uploaded="{{d.avatar}}"
                    ></div>
                </div>
            </div>
            <div class="layui-form-item">
                <text style="color:red;">图片尺寸建议 1:1比例</text>
                <label class="layui-form-label">
                    <text title="必填项" style="color:red;">*</text>
                    封面图</label>
                <div class="layui-input-block">
                    <div class="laytpUpload"
                         data-name="cover"
                         data-dir="xm_game/skym/music/cover"
                         data-accept="image"
                         data-type="ali-oss"
                         data-layVerify="required"
                         data-showChoiceBtn="false"
                         data-uploadedId="{{d.cover}}"
                         data-uploaded="{{d.cover}}"
                    ></div>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    <text title="必填项" style="color:red;">*</text>
                    bpm</label>
                <div class="layui-input-block">
                    <input type="number" name="bpm" value="{{d.bpm}}" lay-verify="required" autocomplete="off" placeholder="请输入bpm"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <text title="必填项" style="color:red;">*</text>
                    音高</label>
                <div class="layui-input-block">
                    <input type="text" name="pitch" value="{{d.pitch}}" lay-verify="required" autocomplete="off" placeholder="请输入音高"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <text title="必填项" style="color:red;">*</text>
                    基础节拍</label>
                <div class="layui-input-block">
                    <input type="number" name="base_beat" value="{{d.base_beat}}" lay-verify="required" autocomplete="off" placeholder="请输入基础节拍"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <text title="必填项" style="color:red;">*</text>
                    节拍</label>
                <div class="layui-input-block">
                    <input type="text" name="time_signature" value="{{d.time_signature}}" lay-verify="required" autocomplete="off" placeholder="请输入节拍"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">
                    <text title="必填项" style="color:red;">*</text>
                    规模</label>
                <div class="layui-input-block">
                    <input type="number" name="scale" value="{{d.scale}}" lay-verify="required" autocomplete="off" placeholder="请输入规模"
                           class="layui-input">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">
                    标签</label>
                <div class="layui-input-block">
                    <div class="xmSelect"
                         data-name="label_id"
                         data-sourceType="route"
                         data-source="/admin.skym.label/index"
                         data-valueField="id"
                         data-textField="name"
                         data-radio="true"
                         data-placeholder="请选择标签"
                         data-selected="{{d.label_id}}"
                    ></div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">  <text title="必填项" style="color:red;">*</text>
                        乐谱内容</label>
                    <div class="layui-input-block">
                        <textarea name="notes"  placeholder="请输入乐谱内容" class="layui-textarea" lay-verify="required">{{d.notes}}</textarea>
                    </div>
                </div>
            </div>

        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="laytp-btn laytp-btn-primary laytp-btn-sm" lay-submit="" lay-filter="laytp-form">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="laytp-btn laytp-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</script>
<form class="layui-form" lay-filter="layui-form">
</form>
<script>
    if(localStorage.getItem("staticDomain")){
        document.write("<link rel='stylesheet' href='" + localStorage.getItem("staticDomain") + "/component/layui/css/layui.css?v=" + localStorage.getItem("version") + "'>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/layui/layui.js?v="+localStorage.getItem("version")+"'><\/script>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/laytp/layuiConfig.js?v="+localStorage.getItem("version")+"'><\/script>");
    }else{
        document.write("<link rel='stylesheet' href='/static/component/layui/css/layui.css?v=" + localStorage.getItem("version") + "'>");
        document.write("<script src='/static/component/layui/layui.js?v="+localStorage.getItem("version")+"'><\/script>");
        document.write("<script src='/static/component/laytp/layuiConfig.js?v="+localStorage.getItem("version")+"'><\/script>");
    }
</script>
<script>
    layui.use(['laytp','colorpicker'],function(){
        let colorpicker = layui.colorpicker;
        let form = layui.form;
        let $ = layui.jquery;
        //获取参数ID
        var id = facade.getUrlParam('id');
        if(!id){
            facade.error('参数ID不能为空');
            return false;
        }

        //获取数据，渲染到对应的节点上
        facade.ajax({
            route: "/admin.skym.music/info",
            data: {id: id},
            successAlert: false,
            showLoading: true
        }).done(function(res){
            if(res.code === 0){
                layui.laytpl($("#form").html()).render(res.data,function(string){
                    $("form").html(string);
                    layui.laytpForm.render();
                    form.render();
                    //常规使用
                    colorpicker.render({
                        elem: '#color_dom' //绑定元素
                        ,color:res.data.color
                        ,change: function(color){ //颜色改变的回调
                            $('#color').val(color);
                        }
                    });

                    //常规使用
                    colorpicker.render({
                        elem: '#bg_color_dom' //绑定元素
                        ,color:res.data.bg_color
                        ,change: function(color){ //颜色改变的回调
                            $('#bg_color').val(color);
                        }
                    });
                });
            }
        });

        form.on('submit(laytp-form)', function(data){
            var btnAnim = layui.button.load({elem:$(this)});
            facade.ajax({
                route:'/admin.skym.music/edit',
                data:data.field
            }).done(function(res){
                if(res.code === 0){
                    parent.layui.layer.close(parent.layui.layer.getFrameIndex(window.name));//关闭当前页
                    parent.layui.table.reload("laytp-table");
                }
                btnAnim.stop();
            }).fail(function(){
                btnAnim.stop();
            });
            return false;
        });
    })
</script>
</body>
</html>